package ks.client.gui.user.listeners;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JFrame;
import javax.swing.JTextField;

import ks.client.UserContext;
import ks.client.controllers.admincommands.PluginUninstallCommand;
import ks.client.controllers.commands.AccountCommandController;
import ks.client.gui.ErrorMessageGUI;
import ks.client.kommander.Action;
import ks.client.lobby.Lobby;
import ks.managers.user.User;
import ks.managers.user.UserManager;

public class UpdateAccountClick implements ActionListener{
	Lobby lobby;
	JTextField old_pass;
	JTextField new_pass;
	String iconName;
	UserContext context;
	User u;
	
	public UpdateAccountClick(Lobby lobby, JTextField old_pass, JTextField new_pass) {
		this.lobby = lobby;
		this.old_pass = old_pass;
		this.new_pass = new_pass;
		context = lobby.getUserContext();
		UserManager um = context.getUserManager();
		u = um.getUser(context.getUser());
		
	}

	/**
	 * 
	 * Button is clicked. 
	 * 
	 */
	public void actionPerformed(ActionEvent e){
		this.iconName = lobby.getAccountUpdateGUI().getPic().getName();
		String old = old_pass.getText();
		String newp = new_pass.getText();
		context.getClient().sha1(old);
		context.getClient().sha1(newp);
		System.out.println(old);
		System.out.println(newp);
			new AccountCommandController(lobby).send(u.getName(), old, newp, iconName);
			
	
	
	
	}
}
